<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>牛只列表</title>
		<link href="css/new_file.css" rel="stylesheet" type="text/css">
		<link href="css/mui.min.css" rel="stylesheet" type="text/css">
		<script charset="UTF-8" src="js/config.js"></script>
		<script charset="UTF-8" src="js/testActivityName.js"></script>
		<script charset="UTF-8" src="js/core.js"></script>
		<script charset="UTF-8" src="js/cipher-core.js"></script>
		<script charset="UTF-8" src="js/tripledes.js"></script>
		<script charset="UTF-8" src="js/mode-ecb.js"></script>
		<script src="js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="js/zepto.min.js"></script>
		<script type="text/javascript" src="js/spin.min.js"></script>
		<script charset="UTF-8" src="js/mui.min.js"></script>
		<script src="js/echarts.min.js"></script>
	</head>
	<style>
		.mui-bar{
			     padding-right: 0px; 
			     padding-left:0px; 
		}
	</style>
	<body>
	<div class="spin"></div>
	<header id="header" class="mui-bar mui-bar-transparent" style="width: 100%;">
			<div class="head-zhjf" style="width: 100%;">
				<img onclick="CattleReturn()" src="images/fanhui@3x.png" class="ryjk-tx">
		
				<div class="head-zhjf-img" onclick="Cowtianjia()">
					<img src="images/tianjia-btn@3x.png">
				</div>
		
				<p>奶牛管理</p>
			</div>
		
			<div class="search-div">
				<div class="g-bd2">
					<div class="search-l-div">
						<div class="seach-l-a">
							<img class="sousuo-acx" src="images/sousuo-btn@3x.png">
							<input id="CattleSeachData" class="xtsz-search-btn" type="text" placeholder="请输入搜索内容" onfocus="if(value==defaultValue){value='';this.style.color='#393e46'}" onblur="if(!value){value=defaultValue;this.style.color='#cdcdcd'}">
		
						</div>
					</div>
					<div class="seach-r-div" onclick="CattleSeach()">
						<img class="cx-div" src="images/sousuo-a-btn@3x.png" />
					</div>
				</div>
			</div>
	</header>
	
		<div style="margin-top: 90px;" class="clear"></div>
		<div >
			<div id="noApplicationRecord">
				<div style="width: 100%;height: 100%;text-align: center;margin-top: 45%;">
					<img src="images/nodata.png" style="width: 200px;height: 140px;"/>
				</div>
			</div>
		</div>
		<div id="hddb" style="position: fixed;right: -63px;bottom: 30px;border-radius: 25px;width: 50px;height: 50px;text-align: center;">
			<img src="img/hddb.png" style="width: 32px;height: 32px;    margin-top: 9px;" onclick="goTop()">
		</div>
		<!-- 疑似发情判断弹框-->
		<div class="nzlb_tc" style="display: none;" id="lu_pan0">
			<div class="nzlb_tc_nr" >
				<div class="nzlb_tc_nr_bt" id="lu_pan_ob">12643 判定揭发情况</div>
				<div class="nzlb_tc_nr_an">
					<a class="nzlb_tc_nr_an_a" cow_id="" id="lu_pan_y" onclick="ShowTangKang(1)">判定发情</a>
					<a class="nzlb_tc_nr_an_a" cow_id="" id="lu_pan_n" onclick="HeadOestrusInterface(3)">判定未发情</a>
				</div>
				<div class="nzlb_tc_nr_qx" onclick="hideysfaq()">取消</div>
			</div>
		</div>
		<!--配种情况弹框-->
		<div class="nzlb_tc" style="display: none;" id="lu_pan1">
			<div class="nzlb_tc_nr" >
				<div class="nzlb_tc_nr_bt" id="lu_pan_ob1">12643 判定揭发情况</div>
				<div class="nzlb_tc_nr_an">
					<a class="nzlb_tc_nr_an_a" cow_id="" style="width: 60%;margin-top: 2px;" onclick="HeadOestrusInterface2(this)">待配</a>
					<a class="nzlb_tc_nr_an_a" cow_id="" style="width: 60%;margin-top: 2px;" onclick="ShowTangKang(2)">配种</a>
					<a class="nzlb_tc_nr_an_a" cow_id="" style="width: 60%;margin-top: 2px;" onclick="ShowTangKang(4)">未配种</a>
				</div>
				<div class="nzlb_tc_nr_qx" onclick="hideysfaq()">取消</div>
			</div>
		</div>
		<!-- 配种精子选择-->
		<div class="nzlb_tc" style="display: none;" id="lu_pan2">
			<div class="nzlb_tc_nr" >
				<div class="nzlb_tc_nr_bt" id="lu_pan_ob2" >12643 判定揭发情况</div>
				<div class="nzlb_tc_nr_an">
					<a class="nzlb_tc_nr_an_a" cow_id=""  onclick="HeadOestrusInterface2(this)">常规冻精</a>
					<a class="nzlb_tc_nr_an_a" cow_id=""  onclick="HeadOestrusInterface2(this)">性控冻精</a>
				</div>
				<div class="nzlb_tc_nr_qx" onclick="hideysfaq()">取消</div>
			</div>
		</div>
		<!--未配种弹框-->
		<div class="nzlb_tc" style="display: none;" id="lu_pan3">
			<div class="nzlb_tc_nr" >
				<div class="nzlb_tc_nr_bt" id="lu_pan_ob3" >12643 判定揭发情况</div>
				<div class="nzlb_tc_nr_an">
					<input id="iptext1" type="text" value="选择未配种原因" style="width: 100%;text-align:center" readonly="readonly">
				</div>
				<div class="nzlb_tc_nr_qx"  style="width: 50%;float: left;background: #2d82ff;color: #fff" onclick="HeadOestrusInterface1(2)">确定</div>
				<div class="nzlb_tc_nr_qx"  style="width: 50%;float: right" onclick="hideysfaq()">取消</div>
			</div>
		</div>
		<!--未配原因-->
		<div class="nzlb_tc" style="display: none;overflow-y: scroll;z-index: 99" id="lu_pan4">
			<div class="head-zhjf">
				<img src="images/fanhui@3x.png" class="ryjk-tx" onclick="hideysfaq()" >
				<p style="color: white;">未配原因</p>
			</div>
		</div>
		<script>
			var CattleSeachData = JSON.parse(localStorage.getItem('CattleSeachData'));
			var numberStr = 2;
			var butStr = 0;
			var noApplicationRecord = document.getElementById('noApplicationRecord');
			var equipmentData = JSON.parse(localStorage.getItem('CattleData'));
			console.log(equipmentData);
			if(equipmentData.length != 20) {
				butStr = 1;
			}
			//绘制单个div
			if(equipmentData.length != 0) {
				huitu();
			}
			

			function liebiao(id) {
				console.log(id);
				var TurnOutNumber = JSON.parse(localStorage.getItem('TurnOutNumber'));
				if(TurnOutNumber == 10) {
					for(var i = 0; i < equipmentData.length; i++) {
						if(equipmentData[i].cowID == id) {
							localStorage.setItem('TurnOutDetails', JSON.stringify(equipmentData[i]));
							window.location = "4.转舍1.html";
						}
					}
				} else {
					for(var i = 0; i < equipmentData.length; i++) {
						if(equipmentData[i].cowID == id) {
							localStorage.setItem('equipmentDetails', JSON.stringify(equipmentData[i]));
						}
					}
					console.log(id);
					window.location = "2.1.1牛只详情.html";
				}
			}

			//获取滚动条当前的位置 
			function getScrollTop() {
				var scrollTop = 0;
				if(document.documentElement && document.documentElement.scrollTop) {
					scrollTop = document.documentElement.scrollTop;
				} else if(document.body) {
					scrollTop = document.body.scrollTop;
				}
				return scrollTop;
			}

			//获取当前可视范围的高度 
			function getClientHeight() {
				var clientHeight = 0;
				if(document.body.clientHeight && document.documentElement.clientHeight) {
					clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
				} else {
					clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
				}
				return clientHeight;
			}

			//获取文档完整的高度 
			function getScrollHeight() {
				return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
			}
			var uLock=true;
			window.onscroll = function() {
//				console.log("x="+getScrollTop()+"  y="+getClientHeight()+" z="+getScrollHeight());
				if(getScrollTop() + getClientHeight() >= getScrollHeight()-6) { //ajax从这里开始
					if(butStr == 1) {
						mui.toast("没有更多数据了")
					} else {
						if (!uLock){
							return;
						}
						uLock=false;
						var keys = JSON.parse(localStorage.getItem('key'));
						var ChooseACowshedData = JSON.parse(localStorage.getItem('ChooseACowshedData'));
						var str = JSON.parse(localStorage.getItem('nainiuCode'));
						var map = {};
						if(str != 1) {
							if(ChooseACowshedData == "null") {
								map.houseID = '';
							} else {
								map.houseID = ChooseACowshedData;
							}
						}
						if (CattleSeachData != '') {
							map.searchKey = CattleSeachData;
						}
						map.key = keys;
						map.page = numberStr;
						map.size = 20;
						map.phoneType = "android";
						map.language = "zh";
						var jsonStr = JSON.stringify(map);
						var ajaxTimeoutTest = $.ajax({
							type: "POST",
							url: url_prefix + "cowManagement",
							dataType: 'JSON',
							 timeout: 10000,
							data: {
								'request': encryptByDES(jsonStr)
							},
							success: function(data) {
								localStorage.setItem('nainiuCode', JSON.stringify(0));
								var str1 = decryptByDESModeEBC(data["result"]); //解密
								var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
								var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
								var datas = JSON.stringify(str2); //转JSON字符串
								var aa = datas.replace(/\\n/g, " "); //去掉换行
								var objs = eval('(' + aa + ')');
								var bb = eval('(' + objs + ')');
								uLock=true;
								if(bb.head.status == 1) {
									if(bb.data.length != 20) {
										butStr = 1;
									}
									if(bb.data.length == 0) {
										mui.toast("没有更多数据了");
									}
									for(var i = 0; i < bb.data.length; i++) {
										equipmentData.push(bb.data[i]);
									}
									console.log(equipmentData);
									numberStr++;
									if(bb.data.length != 0) {
										huitu();
									}
									
								} else {
									mui.alert(bb.head.info);
								}
							},
							complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
								uLock=true;
								localStorage.setItem('nainiuCode', JSON.stringify(0));　
								if(status == 'timeout') { //超时,status还有success,error等值的情况
									ajaxTimeoutTest.abort();　　　　　
									mui.alert("网络请求超时...");　　　　
								}　　
							}
						});
					}
				}
			}
			function huitu() {
				function setDiv(item,i) {
					var reproductive_status = item.reproductive_status;
					if(item.flag == 1){
						var div = '<div class="liebiao-div"  ><div  id="' + item.cowID + '" onclick="liebiao(this.id)" ><img class="liebiao-que-l" src="images/banyuan@3x.png" /><img class="liebiao-que-r" src="images/banyuan-right@3x.png" /><div class="xulieh-div"><p class="xulie-p">' +
							item.deviceNumber +
							'</p><p class="biaoqian-b">' +
							item.STATUS +
							'</p></div><div><div class="liebiao-aa"><p class="liebiao-l">奶牛编号</p><p class="liebiao-r">' +
							item.cowCode +
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">月龄</p><p class="liebiao-r">' +
							item.monthold +
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">胎次</p><p class="liebiao-r">' +
							item.parity+
							'次</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">配次</p><p class="liebiao-r">' +
							item.allocation+
							'次</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">产犊日期</p><p class="liebiao-r">' +
							item.DeliveryDate+
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">泌乳天数</p><p class="liebiao-r">' +
							item.LactationDate+
							'天</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">上次配种日期</p><p class="liebiao-r">' +
							item.Last_mating+
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">配后天数</p><p class="liebiao-r">' +
							item.Last_mating_date+
							'天</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">繁殖状态</p><p class="liebiao-r">' +
							reproductive_status+
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">牛舍</p><p class="liebiao-r">' +
							item.houseName +
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">分群</p><p class="liebiao-r">' +
							item.groupName +
							'</p><div class="clear"></div></div></div></div><div class="fqpd"><div class="fqpd-ss"><p ></p></div>' +
								'<div class="fqpd-ss"><p id="' + i + '" onclick="ShowTQ(this.id)">同期发情</p></div></div><div class="clear"></div></div>'
						return div
					}else{
						var div = '<div class="liebiao-div"  ><div  id="' + item.cowID + '" onclick="liebiao(this.id)" ><img class="liebiao-que-l" src="images/banyuan@3x.png" /><img class="liebiao-que-r" src="images/banyuan-right@3x.png" /><div class="xulieh-div"><p class="xulie-p">' +
							item.deviceNumber +
							'</p><p class="biaoqian-b">' +
							item.STATUS +
							'</p></div><div><div class="liebiao-aa"><p class="liebiao-l">奶牛编号</p><p class="liebiao-r">' +
							item.cowCode +
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">月龄</p><p class="liebiao-r">' +
							item.monthold +
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">胎次</p><p class="liebiao-r">' +
							item.parity+
							'次</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">配次</p><p class="liebiao-r">' +
							item.allocation+
							'次</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">产犊日期</p><p class="liebiao-r">' +
							item.DeliveryDate+
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">泌乳天数</p><p class="liebiao-r">' +
							item.LactationDate+
							'天</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">上次配种日期</p><p class="liebiao-r">' +
							item.Last_mating+
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">配后天数</p><p class="liebiao-r">' +
							item.Last_mating_date+
							'天</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">繁殖状态</p><p class="liebiao-r">' +
							reproductive_status+
							// '</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">奶量</p><p class="liebiao-r">' +
							// item.milk+
							'kg</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">奶量班次1</p><p class="liebiao-r">' +
							item.milk1+
							'kg</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">奶量班次2</p><p class="liebiao-r">' +
							item.milk2+
							'kg</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">奶量班次3</p><p class="liebiao-r">' +
							item.milk3+
							'kg</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">牛舍</p><p class="liebiao-r">' +
							item.houseName +
							'</p><div class="clear"></div></div><div class="liebiao-aa"><p class="liebiao-l">分群</p><p class="liebiao-r">' +
							item.groupName +
							'</p><div class="clear"></div></div></div></div><div class="fqpd"><div class="fqpd-ss"><p id="' + i + '" onclick="ShowRG(this.id)">人工揭发发情</p></div>' +
								'<div class="fqpd-ss"><p id="' + i + '" onclick="ShowTQ(this.id)">同期发情</p></div></div><div class="clear"></div></div>'
						return div
					}
					
				}
				function getnoApplicationData() {
					WPReason();
					var html = ''
					for(var i = 0; i < equipmentData.length; i++) {
						html += setDiv(equipmentData[i],i)
					}
					noApplicationRecord.innerHTML = html
				}
				window.onload = getnoApplicationData()
			}
			//人工判定发情
			var resultAll=0;
			function ShowRG(id) {
				document.getElementById("lu_pan_ob").innerHTML=equipmentData[id].cowCode+"判定揭发情况";
				document.getElementById("lu_pan_ob1").innerHTML=equipmentData[id].cowCode+"配种情况";
				document.getElementById("lu_pan_ob2").innerHTML=equipmentData[id].cowCode+"配种精子选择";
				document.getElementById("lu_pan_ob3").innerHTML=equipmentData[id].cowCode+"未配种情况";
				document.getElementById("lu_pan_y").setAttribute("cow_id",id);
				resultAll=4;
				ShowTangKang(1);
			}
			//同期发情
			function ShowTQ(id) {
				document.getElementById("lu_pan_ob").innerHTML=equipmentData[id].cowCode+"判定揭发情况";
				document.getElementById("lu_pan_ob1").innerHTML=equipmentData[id].cowCode+"配种情况";
				document.getElementById("lu_pan_ob2").innerHTML=equipmentData[id].cowCode+"配种精子选择";
				document.getElementById("lu_pan_ob3").innerHTML=equipmentData[id].cowCode+"未配种情况";
				document.getElementById("lu_pan_y").setAttribute("cow_id",id);
				resultAll=5;
				ShowTangKang(2);
			}
			/*隐藏发情*/
			function hideysfaq(){
				document.body.style.cssText = 'overflow:auto';
				for (i=0;i<=4;i++){
					var lup="lu_pan"+i;
					var weifaq=document.getElementById(lup);
					weifaq.style.display="none";
				}
			}
			//3判定未发情
			function HeadOestrusInterface(result) {
				var map = {};
				map.result = resultAll;//判定未发情
				OestrusInterface(map)
			}
			//2判定发情加未配原因
			function HeadOestrusInterface1(result) {
				var map = {};
				map.result = resultAll;
				map.breeding=$("#iptext1").val();
				OestrusInterface(map)
			}
			//判定发情加配种情况
			function HeadOestrusInterface2(obj) {
				var map = {};
				map.result =resultAll;
				map.breeding=obj.innerHTML;
				OestrusInterface(map)
			}
			/*判定发情情况*/
			function OestrusInterface(map) {
				if (map==undefined){
					var map = {};
				}
				var id=document.getElementById("lu_pan_y").attributes["cow_id"].nodeValue;
				var cow_id=equipmentData[id].cowID;
				var keys = JSON.parse(localStorage.getItem('key'));
				map.key = keys;
				map.cowID = cow_id;
//				map.remark = remark.value;
// 				map.date = paramsName;
				map.phoneType = "android";
				map.language = "zh";
				console.log(map);
				var jsonStr = JSON.stringify(map);
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "estrusDetermination",
					dataType: 'JSON',
					 timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						var str1 = decryptByDESModeEBC(data["result"]); //解密
						var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
						var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str2); //转JSON字符串
						var aa = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							hideysfaq();
							mui.alert("操作成功");
							// tjOestrus();
						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						dismissDialog();
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();
							mui.alert("网络请求超时...");
						}
					}
				});
			}
			//未配种原因列表
			function WPReason() {
				var keys = JSON.parse(localStorage.getItem('key'));
				var map = {};
				map.key = keys;
				map.phoneType = "android";
				map.language = "zh";
				map.ResonType=1;
				var jsonStr = JSON.stringify(map);
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "wpReason",
					dataType: 'JSON',
					timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						var str1 = decryptByDESModeEBC(data["result"]); //解密
						var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
						var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str2); //转JSON字符串
						var aa = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							var  wpdata=bb.data;
							for (i=0;i<wpdata.length;i++) {
								var str='<div class="moban-lb">'
										+'<div class="moban-lb-l" style="width: 100%">'
										+'<a class="ziduan-mb" onclick="hideYuanYing(this)">'+wpdata[i].unmatch+'</a>'
										+'</div>';
								$("#lu_pan4").append(str);
							}
						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						dismissDialog();
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();
							mui.alert("网络请求超时...");
						}
					}
				});
			}
			//1.显示配种情况弹框  1,选择精子类型状态 3.未配弹框
			function ShowTangKang(parm) {
				document.body.style.cssText = 'overflow:hidden';
				var str="lu_pan"+parm;
				var weifaq=document.getElementById(str);
				weifaq.style.display="block";
			}
			//返回未配弹框
			function hideYuanYing(obj) {
				document.body.style.cssText = 'overflow:auto';
				$("#iptext1").val(obj.innerHTML);
				hideysfaq();
				ShowTangKang(3);
			}
function goTop(){
			    //速度
			    var speed = 100;
			    //开启定时器
			    
			    var timer = setInterval(function(){
			        //获取滚动条的高度
			        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
			        //设置滚动的高度
			        document.documentElement.scrollTop = document.body.scrollTop = (scrollTop - speed);
			        //清除定时器
			        speed += 30;
			        if(scrollTop <= 0){
			            clearInterval(timer);
			        }
			    },30)
			}
			
			function showLogin(){  
			    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
			    if (scrollTop > 0) {
			    	$("#hddb").css("right","-3px");
			    } else{
			    	$("#hddb").css("right","-63px");
			    } 
			    //每秒执行一次,showTime()  
			    setTimeout("showLogin()",500);  
			}
			showLogin()
			
		</script>
	</body>

</html>